package Entity;

import java.util.*;
import java.io.Serializable;
/**
 * this is an entity for a general order. 
 * it will save order id, customer id, car number, order date, arrival and leaving date, actual arriving and leaving date
 * and email.
 * @author Sandra Krasko
 *
 */
public class Order implements Serializable
{
	private static final long serialVersionUID = 3082515656276422122L;
	
	private int orderID;
	private String CustomerID;
	private String CarNumber;
	private Date orderDate;
	private boolean isCanceled=false;
	private Date arrivalDate;
	private int parkingLotNumber;
	private Date LeavingDate;
	private Date ActualArrivalDate;
	private Date ActualLeavingDate;
	private static int num=0;
	private String Email;
	
	/**
	 * is the constructor for creating the order. it will set the arrival and leaving to null.
	 * @param CustomerID
	 * @param CarNumber
	 * @param parkingLotNumber
	 * @param arrivalDate
	 * @param LeavingDate
	 * @param Email
	 */
	public Order(String CustomerID, String CarNumber, int parkingLotNumber, Date arrivalDate, Date LeavingDate, String Email)
	{
		this.setOrderID(num++);
		this.setCustomerID(new String(CustomerID));
		this.setCarNumber(new String(CarNumber));
		this.setOrderDate(new Date());
		this.setArrivalDate(arrivalDate);
		this.setParkingLotNumber(parkingLotNumber);
		this.setLeavingDate(LeavingDate);
		this.setEmail(new String(Email));
		ActualArrivalDate=null;
		ActualLeavingDate=null;
	}
	
	/**
	 * is the validation. will check the customer id and car number length and also the mail and the leaving hour.
	 * @param CustomerID
	 * @param CarNumber
	 * @param parkingLotNumber
	 * @param arrivalDate
	 * @param LeavingDate
	 * @param Email
	 * @return
	 */
	public boolean Validate(String CustomerID, String CarNumber, int parkingLotNumber, Date arrivalDate, Date LeavingDate, String Email)
	{
		if (CustomerID.length()!=9)
			return false;
		if(CarNumber.length()!=7)
			return false;
		if(parkingLotNumber<1 || parkingLotNumber>7)
			return false;
		if(new Date().after(arrivalDate))
			return false;
		if(arrivalDate.after(LeavingDate))
			return false;
		if(Email.indexOf('@')==-1 || Email.lastIndexOf('.')<Email.indexOf('@') || Email.startsWith("@"))
			return false;
		return true;
	}

	public String getEmail() {
		return Email;
	}

	public void setEmail(String email) {
		Email = email;
	}

	public Date getActualLeavingDate() {
		return ActualLeavingDate;
	}

	public void setActualLeavingDate(Date actualLeavingDate) {
		ActualLeavingDate = actualLeavingDate;
	}

	public Date getActualArrivalDate() {
		return ActualArrivalDate;
	}

	public void setActualArrivalDate(Date actualArrivalDate) {
		ActualArrivalDate = actualArrivalDate;
	}

	public Date getLeavingDate() {
		return LeavingDate;
	}

	public void setLeavingDate(Date leavingDate) {
		LeavingDate = leavingDate;
	}

	public int getParkingLotNumber() {
		return parkingLotNumber;
	}

	public void setParkingLotNumber(int parkingLotNumber) {
		this.parkingLotNumber = parkingLotNumber;
	}

	public Date getArrivalDate() {
		return arrivalDate;
	}

	public void setArrivalDate(Date arrivalDate) {
		this.arrivalDate = arrivalDate;
	}

	public boolean isCanceled() {
		return isCanceled;
	}

	public void setCanceled(boolean isCanceled) {
		this.isCanceled = isCanceled;
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	public String getCarNumber() {
		return CarNumber;
	}

	public void setCarNumber(String carNumber) {
		CarNumber = carNumber;
	}

	public String getCustomerID() {
		return CustomerID;
	}

	public void setCustomerID(String customerID) {
		CustomerID = customerID;
	}

	public int getOrderID() {
		return orderID;
	}

	public void setOrderID(int orderID) {
		this.orderID = orderID;
	}
}